<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WMS-登录</title>
    <style>
        body {
            margin: 0;
            background-color: #f3f3f4;
        }
        .clearfix:after {
            content: "";
            display:block;
            height:0;
            clear:both;
            visibility:hidden;
        }

        a {
            text-decoration: none;
        }
        .main {
            background: url(/static/imgs/lg_bg2.jpg) repeat  top;
            background-size: cover;
        }
        .footer {
            text-align: center;
            color: #999999;
        }
        .footer p {
            margin:0;
        }

        div.wrap {
            width: 500px;
            /*height: 350px;*/
            /*border: 1px solid green;*/
            position: absolute;
            top:50%;
            left:50%;
            transform: translate(-50%, -60%);
            box-shadow: 0 0 5px #cccccc;
            /*text-align: center;*/
            background-color: ghostwhite;
            opacity: 0.9;
        }

        div.row {
            position: relative;
            height: 70px;
            line-height:70px ;
        }

        div.login {
            width: 290px;
            margin:auto;
        }
        .login .title {
            color: #333;
            margin-top: 20px;
            font-size: 24px;
            text-align: center;
            margin: 25px 0;
        }

        select,input[type=text],input[type=password] {
            width: 260px;
            height: 40px;
            outline:none;
            border: 1px solid #cccccc;
            border-radius: 1px;
            transition: border 0.5s;
            color: #333;
            text-indent: 30px;
            font-size: 18px;
            padding-right: 40px;
        }

        input.captcha {
            width: 90px;
            float: left;
            position: relative;
            top: 2px;
        }

        .captchaImg{
            border:1px solid #cccccc;
            float: right;
            height: 45px;
        }

        select {
            width: 300px;
        }

        input:focus,select:focus {
            border: 1px solid deepskyblue;
        }

        .btn {
            margin-top: 10px;
        }

        .btn button {
            outline: none;
            width: 300px;
            height: 40px;
            line-height: 40px;
            background-color: #69bbfc;
            color: white;
            letter-spacing: .5em;
            border: 0;
            text-align: center;
            border-radius: 2px;
            cursor:pointer;
            font-size: 20px;
            letter-spacing: 0.5em;
        }

        .u-logo {
            width: 20px;
            height: 20px;
            position: absolute;
            left: 6px;
            top: 26px;
        }
        .u-logo-img1 {
            height: 100%;
            background: url(/static/imgs/icon_01.png) -251px -89px no-repeat;
        }
        .u-logo-img2 {
            height: 100%;
            background: url(/static/imgs/icon_01.png) -292px -89px no-repeat;
        }
        .u-logo-img3 {
            height: 100%;
            background: url(/static/imgs/icon_01.png) -16px -89px no-repeat;
        }

        .u-clear {
            width:20px;
            height:20px;
            background: url(/static/imgs/icon_01.png) -147px -89px no-repeat;
            position: absolute;
            right: 0;
            top: 25px;
        }

        .info {
            text-align: left;
            color: red;
            font-size: 14px;
            position: relative;
        }

        .u-info {
            width: 20px;
            height: 20px;
            position: absolute;
            left: 0px;
            top: 0px;
        }
        .info .sms {
            text-indent: 1.1em;
            margin : 5px 0;
            padding-left: 0.2em;
        }

        .u-info-img {
            height: 100%;
            background: url(/static/imgs/icon_01.png) -217px -31px no-repeat;
        }

        .hide {
            visibility: hidden;
        }
    </style>
</head>
<body>
<form action="index.html" id="login-form" >
    <div class="main">
        <div class="wrap">
            <div class="login clearfix">
                <div class="title">
                    <span>WMS-登录</span>
                </div>
                <div class="row">
                    <div class="u-logo">
                        <div class="u-logo-img1"></div>
                    </div>

                    <input type="text" name="userName" autocomplete="off" placeholder="用户名"/>
                    <!--× 图标-->
                    <div class="u-success u-clear hide"></div>
                </div>
                <div class="row">
                    <div class="u-logo">
                        <div class="u-logo-img2"></div>
                    </div>
                    <input type="password" name="password" placeholder="密码"/>
                    <div class="u-success u-clear hide"></div>
                </div>
                <div class="clearfix">
                    <input type="text" class="captcha" name="captcha" maxlength="5" placeholder="验证码" autocomplete="off"/>
                    <img src="/kaptcha.jpg" class="captchaImg" alt="图片验证码">
                </div>
                <div class="info hide">
                    <div class="u-info">
                        <div class="u-info-img"></div>
                    </div>
                    <div class="sms" id="msg">请</div>
                </div>
                <div class="btn">
                    <button id="login-btn"  type="submit">登录</button>
                </div>
                <div class="row" style="text-align:center">
                    <a  href="#">
                        忘记密码?
                    </a>
                    |
                    <a  href="#">
                        联系管理员
                    </a>
                </div>
            </div>

        </div>
    </div>
</form>
<%--<div class="footer">
    <p>友情链接：云和数据 | 集团官网 | 云和教育 | 郑州中心 | 云和教育西安中心 | 云和教育深圳中心</p>
    <p>Copyright © 2013-2017 云和数据信息技术有限公司</p>
</div>--%>

<script src="/static/plugins/jquery-3.2.1.min.js"></script>
<script>
    $(function(){
        initSize();
        var $userName_ipt = $("input[name=userName]");
        var $password_ipt = $("input[name=password]");
        var $captcha_ipt = $("input[name=captcha]");
        var $msg = $("#msg");
        var $chachas = $(".u-clear");
        var $login_form =$("#login-form");  //获取表单对
        //验证码替换事件
        $(".captchaImg").on('click',refreshCode);
        /*绑定提交事件*/
        $login_form.on('submit',function(e){
            e.preventDefault();  //阻止默认提交事件
            var userName = $userName_ipt.val();
            var password = $password_ipt.val();
            var captcha = $captcha_ipt.val();

            if(!userName) {
                $msg.text("请输入用户名");
                $msg.parent().removeClass("hide"); //删除 hide 样式表
                return false;
            }else if(!password) {
                $msg.text("请输入密码");
                $msg.parent().removeClass("hide"); //删除 hide 样式表
                return false;
            }else if(!captcha){
                $msg.text("请输入验证码");
                $msg.parent().removeClass("hide"); //删除 hide 样式表
                return false;
            }
            $.ajax({
                url: '/login/verify',
                type:'post',
                dataType: 'json',
                data: {
                    userName : userName,
                    password : password,
                    captcha : captcha
                },
                success: function(msg){
                    debugger
                    if(msg.code == 1) {
                        location.href = "/";
                    } else {
                        $msg.text(msg.message);
                        $msg.parent().removeClass("hide"); //删除 hide 样式表
                    }

                },
                error: function(){
                    console.log("登陆异常");
                }
            });
        });

        /**实时校验数据状态*/
        $userName_ipt.on("input",function() {
            var $this = $(this);
            if($this.val() ) {
                $this.next().removeClass("hide");//显示 ××
                if($msg.text() == '请输入用户名') {
                    $msg.parent().addClass('hide');
                }
            }else {
                $this.next().addClass("hide");
            }
        });


        $password_ipt.on("input",function() {
            var $this = $(this);
            if($this.val()) {
                $this.next().removeClass("hide");//显示 ××
                if($msg.text()  == '请输入密码') {
                    $msg.parent().addClass('hide');
                }
            }else {
                $this.next().addClass("hide");
            }
        });

        //给× 绑定事件
        $chachas.each(function () {
            $(this).on('click',clearText);
        })


    });


    //清除输入的函数
    function clearText() {
        var $this = $(this);
        $this.prev().val("");
        $this.addClass("hide");
    }

    /**
     * 设置页面大小
     */
    function initSize(){
        document.body.style.height = window.innerHeight + "px";   //  设置页面高度
        var $main = $(".main");
        $main.css("height",window.innerHeight * 1 + "px");
     /*   var $footer = $(".footer");
        $footer.css("height",window.innerHeight * 0.05 + "px");*/
    }

    //刷新验证码
    function refreshCode(){
        $(this).attr("src","/kaptcha.jpg?t=" + new Date().getTime());
    }
</script>
</body>
</html>